Components of Alert Message
Alert messages control trading actions. Below are the key components and their details.
Sample TradingView Strategy: https://www.tradingview.com/script/CZrGSc7m-test-signal-0303-tvl/
Component | Parameters | Remarks |
---|---|---|
Mandatory | Password for Webhook ID | Unique password from the webhook dashboard; must lead every alert message from TradingView. |
Actions | Command to execute (e.g., long, short, flat). | |
Symbol | Trading instrument (e.g., BTCUSD). | |
Quantity (q) | Order size in lots (e.g., q=0.1). | |
Optional | Take Profit (tp) | Take profit of a trade; use points (e.g., tp=300), price (e.g., tpp=2.19), or percentage (e.g., tp=3%). |
Stop Loss (sl) | Stop loss of the trade, Loss limit; use points (e.g., sl=300), price (e.g., slp=2.19), or percentage (e.g., sl=3%). | |
limit price (p) (Currently for MT4 only) | Entry price for limit orders; use points (e.g., p=300), price (e.g., p=5000.0), or percentage (e.g., p=3%). |
Note: "Points" refer to the smallest price unit, varying by symbol and broker. You are recommended to test signals on a demo account first.
To ensure successful trade execution, it is important to follow the correct syntax for the alert message in the following order:
Start with the Webhook ID Password on its own line, followed by:
Actions Symbol Quantity Optional Settings
Example:
PasswordTest
long BTCUSD q=0.1 sl=1000
Orders are executed in market orders in default.
Compulsory values – Password for Webhook ID, Action, symbol and quantity
Example:
PasswordTest
long BTCUSD q=0.1
PasswordTest
short BTCUSD q=0.1 sl=800 tp=1000
TradingView strategy:
{{strategy.market_position}} for a strategy with "long", "flat", and "short" command
Example:
PasswordTest
{{strategy.market_position}} BTCUSD q=0.06
For quantity as a percentage of account balance (qt=percent):
PasswordTest
{{strategy.market_position}} EURUSD q=10 qt=percent
Note: Test this on a demo account due to broker-specific calculations. Some brokers cap lot sizes (e.g., q=100). Use split orders to bypass limits.
Example: Execute trades with 20% of your total account balance
PasswordTest
{{strategy.market_position}} EURUSD q=10 qt=percent
{{strategy.market_position}} EURUSD q=10 qt=percent
Example with price-based SL and point-based TP:
PasswordTest
{{strategy.order.action}} BTCUSD q=0.06 slp=40000 tp=1000
List multiple orders on new lines within the same alert.
Example:
PasswordTest
short BTCUSD q=0.1 sl=800 tp=1000
short BTCUSD q=0.2 sl=800 tp=1000
Compulsory values – Password for Webhook ID, action, symbol
Close action command – flat
Note: It will close all open trades for that symbol.
Example:
PasswordTest
flat US500
It will still close all open trades even quantity or take profit / stop loss is specified:
PasswordTest
flat US500 q=2
For TradingView strategy:
PasswordTest
{{strategy.market_position}} BTCUSD q=0.06
Hence, it is able to automate trades with returning long, short, flat by setting up trading message as below:
To execute a limit order:
Compulsory values – Password for Webhook ID, Action, symbol, quantity and limit price (p).
Note: Due to MT5 settings, setting a positive p value (e.g., p=3000) is not supported, as limit orders cannot be placed above the current market price for long trades or below the current market price for short trades. Use negative values (e.g., p=-3000) to specify prices with points below the market price for long trades or above the market price for short trades, as demonstrated in the examples below.
Example (long BTCUSD at price=91123.0):
PasswordTest
long BTCUSD q=0.1 p=91123.0
Example (long BTCUSD at 3000points below market price, with take profit = +5% of limit order entry price):
PasswordTest
long BTCUSD q=0.1 p=-3000 tp=5%
Example (short BTCUSD at 3000points above market price, with take profit = 1000 points below limit order entry price, and stop loss at 3% above limit order entry price):
PasswordTest
short BTCUSD q=0.1 p=-3000 tp=1000 sl=3%
Example (short BTCUSD at 3000points below market price):
PasswordTest
short BTCUSD q=0.1 p=3000
Add each order on a new line.
Example:
PasswordTest
short BTCUSD q=0.1 p=300 tp=1000
short BTCUSD q=0.1 p=300 tp=1000
Specify an expiry time (e) to automatically cancel an order after the designated time period.
Example:
PasswordTest
short BTCUSD q=0.1 p=-300 tp=1000 e=15
short BTCUSD q=0.1 p=-300 tp=1000 e=30
Use the cancel action command to terminate a limit order.
Note: This will terminate all pending limit orders for the specified symbol.
Example:
PasswordTest
cancel BTCUSD
By adding t=long or t=short, you can cancel only the long or short pending limit orders for that symbol.
Example:
PasswordTest
cancel BTCUSD t=long